<?php

function DateDiff($part, $begin, $end)
{
	$diff = strtotime($end) - strtotime($begin);
	switch($part)
	{
	case "y": $retval = bcdiv($diff, (60 * 60 * 24 * 365)); break;
	case "m": $retval = bcdiv($diff, (60 * 60 * 24 * 30)); break;
	case "w": $retval = bcdiv($diff, (60 * 60 * 24 * 7)); break;
	case "d": $retval = bcdiv($diff, (60 * 60 * 24)); break;
	case "h": $retval = bcdiv($diff, (60 * 60)); break;
	case "n": $retval = bcdiv($diff, 60); break;
	case "s": $retval = $diff; break;
	}
	return $retval;
}



function DateAdd($part, $n, $date)
{
	switch($part)
	{
	case "y": $val = date("Y-m-d H:i:s", strtotime($date ." +$n year")); break;
	case "m": $val = date("Y-m-d H:i:s", strtotime($date ." +$n month")); break;
	case "w": $val = date("Y-m-d H:i:s", strtotime($date ." +$n week")); break;
	case "d": $val = date("Y-m-d H:i:s", strtotime($date ." +$n day")); break;
	case "h": $val = date("Y-m-d H:i:s", strtotime($date ." +$n hour")); break;
	case "n": $val = date("Y-m-d H:i:s", strtotime($date ." +$n minute")); break;
	case "s": $val = date("Y-m-d H:i:s", strtotime($date ." +$n second")); break;
	}
	return $val;
}



?>